<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Local File Access</title>
    <script src="qrc:/qwebchannel.js"></script>
    <script>
        window.onload = function () {
            new QWebChannel(qt.webChannelTransport, function (channel) {
                fileLoader = channel.objects.fileLoader;
                // 确保fileLoader已非空
                if (fileLoader) {
                    console.log('FileLoader object is in JavaScript context.');
                } else {
                    console.error('FileLoader object is not available in JavaScript context.');
                }

                fileLoader.fileContentLoaded.connect(function (fileContent) {
                    // 解码base64内容
                    var content = atob(fileContent);
                    // 在此处使用文件内容
                    console.log(content);
                    // 或者将内容写入DOM元素
                    document.getElementById('output').innerText = content;
                });
                fileLoader.loadFile('D:/test.txt');
            });
        }
    </script>
</head>

<body>
    <p id="output"></p>
</body>

</html>